<template>
  <div class="main-box">
    <!--题目介绍-->
    <!--<div class="mocks-illu-text" v-if="partInfo">{{partInfo.theme}}({{partInfo.score}} points)</div>-->
    <div class="mocks-illu-text" v-html="illuText"></div>
  </div>
</template>

<script>
  import { mapState, mapActions } from 'vuex';

  export default {
    name: "MocksIllustration",
    created () {

    },
    beforeRouteEnter (to, from, next) {
      next(vm => {
        let currentPart = vm.$route.params.currentPart;
        vm.updateCurrentPart(currentPart);
        // 更新头部的上一步的按钮状态
        if (vm.currentPart == 1) {
          vm.updateDisabledPrevBtn(true);
        } else {
          vm.updateDisabledPrevBtn(false);
        }
      });
    },
    computed: {
      ...mapState([
        'paperInfo',
        'currentPart',
        'partInfo',
        'paperId',
        'courseId',
        'paperType'
      ]),

      illuText() {
        if(this.partInfo){
          let str = this.partInfo.theme;
          return ((str && typeof str ==='string')?  str.replace(/\n/g, '<br />').replace(/\t/g, '&nbsp;') : '') + ' ('+this.partInfo.score+' points)';
        }
        return '';
      }

    },
    methods: {
      ...mapActions([
        'updatePartInfo',
        'updateCurrentPart',
        'updateDisabledPrevBtn',
        'updateShowHeaderPart'
      ]),
      submitPaper () {
        let _this = this;
        $.ajax({
          url: 'http://www.ruixinnj.com/report/set_status',
          // url: '/api/mocks/result',
          type: 'post',
          dataType: 'json',
          data: {
            paperId: this.paperId,
            courseId: this.courseId,
            paperType: this.paperType,
            random_string: (typeof random_string == 'string' ? random_string : ''),
            secret_string: (typeof secret_string == 'string' ? secret_string : '')
          },
          success: function (response) {
            if (response.status == 1) {
              let _data = response.data;
              _this.updateShowHeaderPart(false);
              // _this.$router.replace(`/result/${_this.paperId}/1/0`)
              _this.$router.replace(`/result/${_this.paperId}/${_data.result}/${_data.score}`)
            } else {
              layer.msg(response.msg);
            }
          }
        })
      },
    }
  }
</script>

<style scoped>

</style>
